package com.kzw.oa.comm.web;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.kzw.core.util.web.ServletUtils;
import com.kzw.core.web.action.BaseAction;

/**
 * @author kzwang
 */
@Controller
@Scope("prototype")
@SuppressWarnings("unchecked")
public class TestAction extends BaseAction {
	
	private String txt;
	
	/**
	 * 数据处理
	 * */
	public void dm() throws Exception {
		
		DateFormat df = new SimpleDateFormat("yyyyMMdd");
		String fname = df.format(new Date()) + "_点名.txt";
		HttpServletResponse response = getResponse();
		ServletUtils.setFileDownloadHeader(response, fname);
		
		String path = this.getClass().getResource("/md.txt").toURI().getPath();
		File file = new File(path);
		List<String> lines = FileUtils.readLines(file, "UTF-8");
		StringBuffer sb = new StringBuffer();
		
		for(String line : lines) {
			if(StringUtils.isNotBlank(line)) {
				if(!txt.contains(line)) {
					sb.append(line).append(System.getProperty("line.separator"));
				}
			}
		}
		
		IOUtils.write(sb, response.getOutputStream());
	}

	public String getTxt() {
		return txt;
	}

	public void setTxt(String txt) {
		this.txt = txt;
	}
	
}
